/*
 * Authors: Satnam Alag
 * http://www.manning.com/alag/
 * Copyright -- Collective Intelligence in Action
 * Updated: Filipe Ferraz Salgado  (filipesalgado@hotmail.com)
 *          Alexandre Albano       (aalbano@gmail.com)
 *          Instituto de Matemática e Estatística
 *          Universidade de São Paulo
 * 
 */

package br.org.groupware_workbench.commonalgorithms.analisadortextual_1_1.com.alag.ci.textanalysis.lucene.impl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import br.org.groupware_workbench.commonalgorithms.analisadortextual_1_1.com.alag.ci.textanalysis.SynonymsCache;

public class SynonymsCacheImpl extends CacheImpl implements SynonymsCache {
    private Map<String,List<String>> synonyms = null;
    
    public SynonymsCacheImpl(String[] stopWords) throws IOException {
    	super(stopWords);
    	this.synonyms = new HashMap<String,List<String>>();
    }
    
    public SynonymsCacheImpl(Map<String, List<String>> mapWordSynonyms, String[] stopWords) throws IOException {
    	super(stopWords);
        this.synonyms = new HashMap<String,List<String>>();
        List<String> listSynonym = new ArrayList<String>();
//        ciList.add("ci");
//        this.synonyms.put(getStemmedText("collective intelligence"), ciList);
        
        if(mapWordSynonyms != null) {
        	for (Iterator iter = mapWordSynonyms.entrySet().iterator(); iter.hasNext();) {
        		Map.Entry<String, List<String>> mapEntry = (Entry<String, List<String>>) iter.next();

        		List<String> actualListSynonyms = mapEntry.getValue();

        		listSynonym.addAll(actualListSynonyms);
        		this.synonyms.put(getStemmedText(mapEntry.getKey()), listSynonym);
        	}
        }
    }
    
    public List<String> getSynonym(String text) throws IOException{
        return this.synonyms.get(getStemmedText(text));  
    }
}
